﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kovan.Model.Common;
using Kovan.Library.Json;
using Kovan.Model.Enums;
using System.Web.Security;
using Kovan.BLL.UserCenter;

namespace Kovan.UI.Areas.Manage.Controllers
{
    public class ManageControllerBase : Controller
    {

        /// <summary>
        /// Gets or sets当前登录用户信息(保存Session)
        /// </summary>
        public static User CurrentUser
        {
            get { return BUserLogin.GetUser(); }
            set { BUserLogin.SetUser(value); }
        }

        public string GetResultCode(ResultCode<string> code)
        {
            return code.ToJson();
        }

        /// <summary>
        /// 在调用操作方法前调用，用于验证访问权限
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                RedirectToAction("Index", "Account");
                //没有登录
            }
        }

        /// <summary>
        /// 操作成功 返回json数据
        /// </summary>
        /// <param name="message">描述</param>
        /// <returns></returns>
        public string GetSucceedCode(string message, string navTabId, string forwardUrl, string title)
        {
            ResultCode<string> code = new ResultCode<string>();
            code.statusCode = ((int)StatusEnum.Succeed).ToString();
            code.message = message;
            code.callbackType = "";
            code.forwardUrl = forwardUrl;
            code.navTabId = navTabId;
            code.title = title;
            return code.ToJson();
        }

        /// <summary>
        /// 操作失败 返回json数据
        /// </summary>
        /// <param name="message">描述</param>
        /// <returns></returns>
        public string GetFailCode(string message, string navTabId, string forwardUrl, string title)
        {
            ResultCode<string> code = new ResultCode<string>();
            code.statusCode = ((int)StatusEnum.Fail).ToString();
            code.message = message;
            code.callbackType = "";
            code.forwardUrl = forwardUrl;
            code.navTabId = navTabId;
            code.title = title;
            return code.ToJson();
        }


    }
}
